// This file is a part of ChaosDB.
// Copyright (C) 2012 ChaoJianPeng
// email:chaojianpeng@gmail.com
//
// ChaosDB is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// ChaosDB is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

/*
 * logger.cpp
 *
 *  Created on: 2012-3-11
 *      Author: chao
 */
#include "stdlib.h"
#include "logger.h"
#include "stdio.h"
#include "time.h"

FILE* systemLog;


void loggerInit() {
	char slogName[100], stdLogName[100];
	sprintf(slogName, "log/systemlog-%d", int(time(NULL)));
	systemLog = fopen(slogName, "w");
	sprintf(stdLogName, "log/stdlog-%d", int(time(NULL)));
	freopen(stdLogName, "w", stdout);
}

void systemLogger(char* s) {
	char timeStr[100];
	struct tm *newtime;
	time_t ltime;
	ltime = time(NULL);
	newtime = localtime(&ltime);
	strftime(timeStr, sizeof(timeStr), "%x-%X", newtime);
	fprintf(systemLog, "%s -- %s\n", timeStr, s);
	// 每次都要fflush
	fflush(systemLog);
}


